#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;

struct Status {
    int x, y, z;
    int t;
};

char maze[30][30][30];
bool mark[30][30][30];
queue<Status> status_queue;

int go[][3] = {
    1, 0, 0,
    -1, 0, 0,
    0, 1, 0,
    0, -1, 0,
    0, 0, 1,
    0, 0, -1
};

int BFS(int end_x, int end_y, int end_z, int L, int R, int C);

int main(int argc, char const* argv[])
{
    int L, R, C;
    while (scanf("%d%d%d", &L, &R, &C) != EOF) {
        if (L == 0 && R == 0 && C == 0)
            break;
        int start_x, start_y, start_z;
        int end_x, end_y, end_z;
        for (int i = 0; i < L; i++) {
            for (int j = 0; j < R; j++) {
                for (int k = 0; k < C; k++) {
                    scanf(" %c", &maze[i][j][k]);
                    mark[i][j][k] = false;
                    if (maze[i][j][k] == 'S') {
                        start_x = i;
                        start_y = j;
                        start_z = k;
                    }
                    if (maze[i][j][k] == 'E') {
                        end_x = i;
                        end_y = j;
                        end_z = k;
                    }
                }
            }
        }

        Status start_status;
        start_status.x = start_x;
        start_status.y = start_y;
        start_status.z = start_z;
        start_status.t = 0;
        while (!status_queue.empty())
            status_queue.pop();
        status_queue.push(start_status);
        mark[start_x][start_y][start_z] = true;

        int min_time = BFS(end_x, end_y, end_z, L, R, C);

        if (min_time == -1)
            printf("Trapped!\n");
        else
            printf("Escaped in %d minute(s).\n", min_time);
    }
    return 0;
}

int BFS(int end_x, int end_y, int end_z, int L, int R, int C)
{
    while (!status_queue.empty()) {
        Status current_status = status_queue.front();
        status_queue.pop();
        //扩充新状态
        int new_x, new_y, new_z;
        for (int i = 0; i < 6; i++) {
            new_x = current_status.x + go[i][0];
            new_y = current_status.y + go[i][1];
            new_z = current_status.z + go[i][2];
            if (new_x < 0 || new_x >= L || new_y < 0 || new_y >= R || new_z < 0 || new_z >= C)
                continue;
            if (mark[new_x][new_y][new_z])
                continue;
            if (maze[new_x][new_y][new_z] == '#')
                continue;
            Status new_status;
            new_status.x = new_x;
            new_status.y = new_y;
            new_status.z = new_z;
            new_status.t = current_status.t + 1;
            if (new_x == end_x && new_y == end_y && new_z == end_z) {
                return new_status.t;
            }
            mark[new_x][new_y][new_z] = true;
            status_queue.push(new_status);
        }
    }
    return -1;
}